{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7953092e-e313-4fb5-82ab-ce1d42f4c1a9",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "# Multi Fabric - Commissioning and Interactions\n",
    "\n",
    "<a href=\"http://35.236.121.59/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fproject-chip%2Fconnectedhomeip&urlpath=lab%2Ftree%2Fconnectedhomeip%2Fdocs%2Fguides%2Frepl%2FMatter%2520-%2520Multi%2520Fabric%2520Commissioning.ipynb&branch=master\">\n",
    "<img src=\"https://i.ibb.co/hR3yWsC/launch-playground.png\" alt=\"drawing\" width=\"130\"/>\n",
    "</a>\n",
    "<br></br>\n",
    "\n",
    "This walks through creating multiple controllers on multiple fabrics, using those controllers to commission a target onto those fabrics and finally, interacting with them using the interaction model."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c8aae2cc-41fa-4101-a744-c725be5f034c",
   "metadata": {},
   "source": [
    "## CertificateAuthority, FabricAdmins and Controllers\n",
    "\n",
    "The `CertificateAuthorityManager` class manages a set of `CertificateAuthority` instances (both present in `matter.CertificateAuthority. package). a `CertificateAuthority` represents an operational root of trust, a Root Certificate Authority (CA) with a root key pair with the associated public key (i.e \"Root PK\"). The `CertificateAuthority` class manages a list of `FabricAdmins` adminstering a fabric within that CA.\n",
    "\n",
    "The `FabricAdmin` class (present in the `matter.FabricAdmin` package) is responsible for administering a fabric. It houses the Fabric ID and is managed by a `CertificateAuthority`.\n",
    "\n",
    "The `FabricAdmin` can be used to vend `ChipDeviceController` objects that represent a controller instance with a specific identity grounded in the admin's fabric. This controller can then be used to commission and interact with devices."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f2e9f8d-eb79-494f-adac-efefdba7165f",
   "metadata": {},
   "source": [
    "## Clear Persisted Storage\n",
    "\n",
    "Let's clear out our persisted storage (if one exists) to start from a clean slate."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b351b723-9849-430d-ad4e-f699897416d1",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os, subprocess\n",
    "\n",
    "if os.path.isfile('/tmp/repl-storage.json'):\n",
    "    os.remove('/tmp/repl-storage.json')\n",
    "\n",
    "# So that the all-clusters-app won't boot with stale prior state.    \n",
    "os.system('rm -rf /tmp/chip_*')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f50759eb-3511-4312-9cfd-7431dcb9366a",
   "metadata": {
    "tags": []
   },
   "source": [
    "## Initialization\n",
    "\n",
    "Let's first begin setting up by importing some key modules that are needed to make it easier for us to interact with the Matter stack.\n",
    "\n",
    "`ReplStartup.py` is run within the global namespace. This results in all of its imports being made available here.\n",
    "\n",
    "> **NOTE**: _This is not needed if you launch the REPL from the command-line._"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "72f25a72-0b7e-41d5-a9ef-18af8a54ec39",
   "metadata": {
    "scrolled": true,
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "<span style=\"font-weight: bold\"> Replacing </span> store path .<span style=\"color: #800080; text-decoration-color: #800080\">/credentials/development/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">paa-root-certs</span> with \n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">/home/root/repos/connectedhomeip/credentials/development/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">paa-root-certs</span>\n",
       "Note that you are still running from \n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">/home/root/repos/connectedhomeip/docs/development_controllers/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">matter-repl</span> so other relative\n",
       "paths may be off.\n",
       "                    \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n",
       "\u001b[1m Replacing \u001b[0m store path .\u001b[35m/credentials/development/\u001b[0m\u001b[95mpaa-root-certs\u001b[0m with \n",
       "\u001b[35m/home/root/repos/connectedhomeip/credentials/development/\u001b[0m\u001b[95mpaa-root-certs\u001b[0m\n",
       "Note that you are still running from \n",
       "\u001b[35m/home/root/repos/connectedhomeip/docs/development_controllers/\u001b[0m\u001b[95mmatter-repl\u001b[0m so other relative\n",
       "paths may be off.\n",
       "                    \n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1738152867.148313][2264454:2264454] CHIP:CTL: Setting attestation nonce to random value\n",
      "[1738152867.148534][2264454:2264454] CHIP:CTL: Setting CSR nonce to random value\n",
      "[1738152867.160741][2264454:2264454] CHIP:DL: NVS set: chip-factory/unique-id = \"3844ABE883465BB4\"\n",
      "[1738152867.161683][2264454:2264454] CHIP:DL: NVS set: chip-factory/vendor-id = 65521 (0xFFF1)\n",
      "[1738152867.162893][2264454:2264454] CHIP:DL: NVS set: chip-factory/product-id = 32769 (0x8001)\n",
      "[1738152867.164421][2264454:2264454] CHIP:DL: NVS set: chip-counters/reboot-count = 1 (0x1)\n",
      "[1738152867.165934][2264454:2264454] CHIP:DL: NVS set: chip-counters/total-operational-hours = 0 (0x0)\n",
      "[1738152867.167463][2264454:2264454] CHIP:DL: NVS set: chip-counters/boot-reason = 0 (0x0)\n",
      "[1738152867.168925][2264454:2264454] CHIP:DL: NVS set: chip-config/regulatory-location = 0 (0x0)\n",
      "[1738152867.170369][2264454:2264454] CHIP:DL: NVS set: chip-config/location-capability = 2 (0x2)\n",
      "[1738152867.170831][2264454:2264454] CHIP:DL: Got Ethernet interface: enp2s0\n",
      "[1738152867.171003][2264454:2264454] CHIP:DL: Found the primary Ethernet interface:enp2s0\n",
      "[1738152867.171166][2264454:2264454] CHIP:DL: Got WiFi interface: wlp3s0\n",
      "[1738152867.171348][2264454:2264454] CHIP:DL: Found the primary WiFi interface:wlp3s0\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #00ff00; text-decoration-color: #00ff00\">─────────────────────────────────────────────────── </span>Matter REPL<span style=\"color: #00ff00; text-decoration-color: #00ff00\"> ───────────────────────────────────────────────────</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[92m─────────────────────────────────────────────────── \u001b[0mMatter REPL\u001b[92m ───────────────────────────────────────────────────\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "            \n",
       "\n",
       "<span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">            Welcome to the Matter Python REPL!</span>\n",
       "\n",
       "<span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">            For help, please type </span><span style=\"color: #008000; text-decoration-color: #008000; font-weight: bold\">matterhelp()</span>\n",
       "\n",
       "<span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">            To get more information on a particular object/class, you can pass</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">            that into </span><span style=\"color: #008000; text-decoration-color: #008000; font-weight: bold\">matterhelp()</span><span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\"> as well.</span>\n",
       "\n",
       "<span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">            </span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n",
       "            \n",
       "\n",
       "\u001b[1;34m            Welcome to the Matter Python REPL!\u001b[0m\n",
       "\n",
       "\u001b[1;34m            For help, please type \u001b[0m\u001b[1;32mmatterhelp\u001b[0m\u001b[1;32m(\u001b[0m\u001b[1;32m)\u001b[0m\n",
       "\n",
       "\u001b[1;34m            To get more information on a particular object/class, you can pass\u001b[0m\n",
       "\u001b[1;34m            that into \u001b[0m\u001b[1;32mmatterhelp\u001b[0m\u001b[1;32m(\u001b[0m\u001b[1;32m)\u001b[0m\u001b[1;34m as well.\u001b[0m\n",
       "\n",
       "\u001b[1;34m            \u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #00ff00; text-decoration-color: #00ff00\">───────────────────────────────────────────────────────────────────────────────────────────────────────────────────</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[92m───────────────────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2025-01-29 13:14:27 ThinkPad matter.storage[2264454] ERROR [Errno 2] No such file or directory: '/tmp/repl-storage.json'\n",
      "2025-01-29 13:14:27 ThinkPad matter.storage[2264454] CRITICAL Could not load configuration from /tmp/repl-storage.json - resetting configuration...\n",
      "2025-01-29 13:14:27 ThinkPad matter.storage[2264454] WARNING No valid SDK configuration present - clearing out configuration\n",
      "2025-01-29 13:14:27 ThinkPad matter.storage[2264454] WARNING No valid REPL configuration present - clearing out configuration\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">The following objects have been created:</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n",
       "\n",
       "\u001b[34mThe following objects have been created:\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">        <span style=\"color: #800000; text-decoration-color: #800000\">certificateAuthorityManager</span><span style=\"color: #000080; text-decoration-color: #000080\">:    Manages a list of CertificateAuthority instances.</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">        </span><span style=\"color: #800000; text-decoration-color: #800000\">caList</span><span style=\"color: #000080; text-decoration-color: #000080\">:                         The list of CertificateAuthority instances.</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">        </span><span style=\"color: #800000; text-decoration-color: #800000\">caList</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">[</span><span style=\"color: #800000; text-decoration-color: #800000\">n</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">]</span><span style=\"color: #800000; text-decoration-color: #800000\">.adminList</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">[</span><span style=\"color: #800000; text-decoration-color: #800000\">m</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">]</span><span style=\"color: #000080; text-decoration-color: #000080\">:         A specific FabricAdmin object at index m for the nth CertificateAuthority </span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">instance.</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "        \u001b[31mcertificateAuthorityManager\u001b[0m\u001b[34m:    \u001b[0m\u001b[34mManages a list of CertificateAuthority instances.\u001b[0m\n",
       "\u001b[34m        \u001b[0m\u001b[31mcaList\u001b[0m\u001b[34m: \u001b[0m\u001b[34m        \u001b[0m\u001b[34m        \u001b[0m\u001b[34m        \u001b[0m\u001b[34mThe list of CertificateAuthority instances.\u001b[0m\n",
       "\u001b[34m        \u001b[0m\u001b[31mcaList\u001b[0m\u001b[1;31m[\u001b[0m\u001b[31mn\u001b[0m\u001b[1;31m]\u001b[0m\u001b[31m.adminList\u001b[0m\u001b[1;31m[\u001b[0m\u001b[31mm\u001b[0m\u001b[1;31m]\u001b[0m\u001b[34m: \u001b[0m\u001b[34m        \u001b[0m\u001b[34mA specific FabricAdmin object at index m for the nth CertificateAuthority \u001b[0m\n",
       "\u001b[34minstance.\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">Default CHIP Device Controller </span><span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">(</span><span style=\"color: #000080; text-decoration-color: #000080\">NodeId: </span><span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">112233</span><span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">)</span><span style=\"color: #000080; text-decoration-color: #000080\">: has been initialized to manage </span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">caList[</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">0</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">].adminList[</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">0</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">]</span><span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\"> (FabricId = </span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">1</span><span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">), and is available as </span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">devCtrl</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n",
       "\n",
       "\u001b[34mDefault CHIP Device Controller \u001b[0m\u001b[1;34m(\u001b[0m\u001b[34mNodeId: \u001b[0m\u001b[1;34m112233\u001b[0m\u001b[1;34m)\u001b[0m\u001b[34m: has been initialized to manage \u001b[0m\u001b[1;31mcaList\u001b[0m\u001b[1;31m[\u001b[0m\u001b[1;31m0\u001b[0m\u001b[1;31m]\u001b[0m\u001b[1;31m.adminList\u001b[0m\u001b[1;31m[\u001b[0m\u001b[1;31m0\u001b[0m\u001b[1;31m]\u001b[0m\u001b[1;34m \u001b[0m\u001b[1;34m(\u001b[0m\u001b[1;34mFabricId = \u001b[0m\n",
       "\u001b[1;34m1\u001b[0m\u001b[1;34m)\u001b[0m\u001b[1;34m, and is available as \u001b[0m\u001b[1;31mdevCtrl\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%reset -f\n",
    "import importlib.util\n",
    "spec = importlib.util.find_spec('matter.ReplStartup')\n",
    "%run {spec.origin} --debug"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d79775d7-2ebb-4d05-9f2f-c7859802dc98",
   "metadata": {},
   "source": [
    "At startup, the `certificateAuthorityManager` within REPL will attempt to find `CertificateAuthority` instances present in persistent storage.If it can't find any (as is the case here), it will create a new `CertificateAuthority` instance at CA index 0. This `CertificateAuthority` instance will construct a default `FabricAdmin` object on FabricAdmin index 0 with a Fabric ID = 1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "030ecc69-bad4-476f-95d5-cb593597cad6",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #000080; text-decoration-color: #000080\">╭───────────────────────────── </span><span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">&lt;</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">class</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #008000; text-decoration-color: #008000\">'matter.FabricAdmin.FabricAdmin'</span><span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">&gt;</span><span style=\"color: #000080; text-decoration-color: #000080\"> ─────────────────────────────╮</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span> <span style=\"color: #008080; text-decoration-color: #008080\">Administers a fabric associated with a unique FabricID under a given CertificateAuthority</span>        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span> <span style=\"color: #008080; text-decoration-color: #008080\">instance.</span>                                                                                        <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span> <span style=\"color: #008000; text-decoration-color: #008000\">╭──────────────────────────────────────────────────────────────────────────────────────────────╮</span> <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span> <span style=\"color: #008000; text-decoration-color: #008000\">│</span> <span style=\"font-weight: bold\">&lt;</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">matter.FabricAdmin.FabricAdmin</span><span style=\"color: #000000; text-decoration-color: #000000\"> object at </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0x74c3436d78e0</span><span style=\"font-weight: bold\">&gt;</span>                                      <span style=\"color: #008000; text-decoration-color: #008000\">│</span> <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span> <span style=\"color: #008000; text-decoration-color: #008000\">╰──────────────────────────────────────────────────────────────────────────────────────────────╯</span> <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                                  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>              <span style=\"color: #808000; text-decoration-color: #808000; font-style: italic\">caIndex</span> = <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span>                                                                         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-style: italic\">certificateAuthority</span> = <span style=\"font-weight: bold\">&lt;</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">matter.CertificateAuthority.CertificateAuthority</span><span style=\"color: #000000; text-decoration-color: #000000\"> object at </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0x74c32c8ba680</span><span style=\"font-weight: bold\">&gt;</span> <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>             <span style=\"color: #808000; text-decoration-color: #808000; font-style: italic\">fabricId</span> = <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span>                                                                         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>             <span style=\"color: #808000; text-decoration-color: #808000; font-style: italic\">vendorId</span> = <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">65521</span>                                                                     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">╰──────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[34m╭─\u001b[0m\u001b[34m────────────────────────────\u001b[0m\u001b[34m \u001b[0m\u001b[1;34m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'matter.FabricAdmin.FabricAdmin'\u001b[0m\u001b[1;34m>\u001b[0m\u001b[34m \u001b[0m\u001b[34m────────────────────────────\u001b[0m\u001b[34m─╮\u001b[0m\n",
       "\u001b[34m│\u001b[0m \u001b[36mAdministers a fabric associated with a unique FabricID under a given CertificateAuthority\u001b[0m        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m \u001b[36minstance.\u001b[0m                                                                                        \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m \u001b[32m╭──────────────────────────────────────────────────────────────────────────────────────────────╮\u001b[0m \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m \u001b[32m│\u001b[0m \u001b[1m<\u001b[0m\u001b[1;95mmatter.FabricAdmin.FabricAdmin\u001b[0m\u001b[39m object at \u001b[0m\u001b[1;36m0x74c3436d78e0\u001b[0m\u001b[1m>\u001b[0m                                      \u001b[32m│\u001b[0m \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m \u001b[32m╰──────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                                  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m              \u001b[3;33mcaIndex\u001b[0m = \u001b[1;36m1\u001b[0m                                                                         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m \u001b[3;33mcertificateAuthority\u001b[0m = \u001b[1m<\u001b[0m\u001b[1;95mmatter.CertificateAuthority.CertificateAuthority\u001b[0m\u001b[39m object at \u001b[0m\u001b[1;36m0x74c32c8ba680\u001b[0m\u001b[1m>\u001b[0m \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m             \u001b[3;33mfabricId\u001b[0m = \u001b[1;36m1\u001b[0m                                                                         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m             \u001b[3;33mvendorId\u001b[0m = \u001b[1;36m65521\u001b[0m                                                                     \u001b[34m│\u001b[0m\n",
       "\u001b[34m╰──────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "inspect(caList[0].adminList[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8d9e6c95-5488-4a9c-87c7-4cfa2dda7d42",
   "metadata": {},
   "source": [
    "The Newly created `FabricAdmin` will automatically construct a device controller (`devCtrl`) on it's own fabric. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a5c5b564-2d16-4790-8659-a7f7f304df98",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #000080; text-decoration-color: #000080\">╭────────────────── </span><span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">&lt;</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">class</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #008000; text-decoration-color: #008000\">'matter.ChipDeviceCtrl.ChipDeviceController'</span><span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">&gt;</span><span style=\"color: #000080; text-decoration-color: #000080\"> ───────────────────╮</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span> <span style=\"color: #008080; text-decoration-color: #008080\">The ChipDeviceCommissioner binding, named as ChipDeviceController</span>                       <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span> <span style=\"color: #008000; text-decoration-color: #008000\">╭─────────────────────────────────────────────────────────────────────────────────────╮</span> <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span> <span style=\"color: #008000; text-decoration-color: #008000\">│</span> <span style=\"font-weight: bold\">&lt;</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">matter.ChipDeviceCtrl.ChipDeviceController</span><span style=\"color: #000000; text-decoration-color: #000000\"> object at </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0x74c32c8baa10</span><span style=\"font-weight: bold\">&gt;</span>                 <span style=\"color: #008000; text-decoration-color: #008000\">│</span> <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span> <span style=\"color: #008000; text-decoration-color: #008000\">╰─────────────────────────────────────────────────────────────────────────────────────╯</span> <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>                                                                                         <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>      <span style=\"color: #808000; text-decoration-color: #808000; font-style: italic\">activeList</span> = <span style=\"font-weight: bold\">{&lt;</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">matter.ChipDeviceCtrl.ChipDeviceController</span><span style=\"color: #000000; text-decoration-color: #000000\"> object at </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0x74c32c8baa10</span><span style=\"font-weight: bold\">&gt;}</span> <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>         <span style=\"color: #808000; text-decoration-color: #808000; font-style: italic\">caIndex</span> = <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span>                                                                     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>         <span style=\"color: #808000; text-decoration-color: #808000; font-style: italic\">devCtrl</span> = <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">c_void_p</span><span style=\"font-weight: bold\">(</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">128380733235904</span><span style=\"font-weight: bold\">)</span>                                             <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>     <span style=\"color: #808000; text-decoration-color: #808000; font-style: italic\">fabricAdmin</span> = <span style=\"font-weight: bold\">&lt;</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">matter.FabricAdmin.FabricAdmin</span><span style=\"color: #000000; text-decoration-color: #000000\"> object at </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0x74c3436d78e0</span><span style=\"font-weight: bold\">&gt;</span>               <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>        <span style=\"color: #808000; text-decoration-color: #808000; font-style: italic\">fabricId</span> = <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span>                                                                     <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>        <span style=\"color: #808000; text-decoration-color: #808000; font-style: italic\">isActive</span> = <span style=\"color: #00ff00; text-decoration-color: #00ff00; font-style: italic\">True</span>                                                                  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>            <span style=\"color: #808000; text-decoration-color: #808000; font-style: italic\">name</span> = <span style=\"color: #008000; text-decoration-color: #008000\">'caIndex(1)/fabricId(0x0000000000000001)/nodeId(0x000000000001B669)'</span>  <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span>          <span style=\"color: #808000; text-decoration-color: #808000; font-style: italic\">nodeId</span> = <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">112233</span>                                                                <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-style: italic\">pairingDelegate</span> = <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">c_void_p</span><span style=\"font-weight: bold\">(</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">128380733235776</span><span style=\"font-weight: bold\">)</span>                                             <span style=\"color: #000080; text-decoration-color: #000080\">│</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">╰─────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[34m╭─\u001b[0m\u001b[34m─────────────────\u001b[0m\u001b[34m \u001b[0m\u001b[1;34m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'matter.ChipDeviceCtrl.ChipDeviceController'\u001b[0m\u001b[1;34m>\u001b[0m\u001b[34m \u001b[0m\u001b[34m──────────────────\u001b[0m\u001b[34m─╮\u001b[0m\n",
       "\u001b[34m│\u001b[0m \u001b[36mThe ChipDeviceCommissioner binding, named as ChipDeviceController\u001b[0m                       \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m \u001b[32m╭─────────────────────────────────────────────────────────────────────────────────────╮\u001b[0m \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m \u001b[32m│\u001b[0m \u001b[1m<\u001b[0m\u001b[1;95mmatter.ChipDeviceCtrl.ChipDeviceController\u001b[0m\u001b[39m object at \u001b[0m\u001b[1;36m0x74c32c8baa10\u001b[0m\u001b[1m>\u001b[0m                 \u001b[32m│\u001b[0m \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m \u001b[32m╰─────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m                                                                                         \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m      \u001b[3;33mactiveList\u001b[0m = \u001b[1m{\u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mmatter.ChipDeviceCtrl.ChipDeviceController\u001b[0m\u001b[39m object at \u001b[0m\u001b[1;36m0x74c32c8baa10\u001b[0m\u001b[1m>\u001b[0m\u001b[1m}\u001b[0m \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m         \u001b[3;33mcaIndex\u001b[0m = \u001b[1;36m1\u001b[0m                                                                     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m         \u001b[3;33mdevCtrl\u001b[0m = \u001b[1;35mc_void_p\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m128380733235904\u001b[0m\u001b[1m)\u001b[0m                                             \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m     \u001b[3;33mfabricAdmin\u001b[0m = \u001b[1m<\u001b[0m\u001b[1;95mmatter.FabricAdmin.FabricAdmin\u001b[0m\u001b[39m object at \u001b[0m\u001b[1;36m0x74c3436d78e0\u001b[0m\u001b[1m>\u001b[0m               \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m        \u001b[3;33mfabricId\u001b[0m = \u001b[1;36m1\u001b[0m                                                                     \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m        \u001b[3;33misActive\u001b[0m = \u001b[3;92mTrue\u001b[0m                                                                  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m            \u001b[3;33mname\u001b[0m = \u001b[32m'caIndex\u001b[0m\u001b[32m(\u001b[0m\u001b[32m1\u001b[0m\u001b[32m)\u001b[0m\u001b[32m/fabricId\u001b[0m\u001b[32m(\u001b[0m\u001b[32m0x0000000000000001\u001b[0m\u001b[32m)\u001b[0m\u001b[32m/nodeId\u001b[0m\u001b[32m(\u001b[0m\u001b[32m0x000000000001B669\u001b[0m\u001b[32m)\u001b[0m\u001b[32m'\u001b[0m  \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m          \u001b[3;33mnodeId\u001b[0m = \u001b[1;36m112233\u001b[0m                                                                \u001b[34m│\u001b[0m\n",
       "\u001b[34m│\u001b[0m \u001b[3;33mpairingDelegate\u001b[0m = \u001b[1;35mc_void_p\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m128380733235776\u001b[0m\u001b[1m)\u001b[0m                                             \u001b[34m│\u001b[0m\n",
       "\u001b[34m╰─────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "inspect(devCtrl)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b793def3-10ff-4f86-a84a-fce81b7a86a4",
   "metadata": {},
   "source": [
    "### Commission onto Fabric 1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a84a90a5-726f-4634-a148-3860ba3ba0fc",
   "metadata": {},
   "source": [
    "#### Launch Server\n",
    "\n",
    "Let's launch an instance of the `chip-all-clusters-app`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b8b08b57-61a7-4c3e-8acc-cf4d78a67f55",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time, os\n",
    "import subprocess\n",
    "os.system('pkill -f chip-all-clusters-app')\n",
    "time.sleep(1)\n",
    "\n",
    "appPath = '../../../out/linux-x64-all-clusters/chip-all-clusters-app'\n",
    "process = subprocess.Popen(appPath, stdout=subprocess.DEVNULL)\n",
    "time.sleep(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cdbc86a0-24ca-4d1b-85f6-1d812a190817",
   "metadata": {},
   "source": [
    "#### Commission Target\n",
    "\n",
    "Commission the target onto Fabric 1 using the default device controller instance with a NodeId of 2."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "cde97ce7-6478-45fd-b985-103b09d8dfa9",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
      ],
      "text/plain": []
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001b[1;36m2\u001b[0m"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "await devCtrl.CommissionOnNetwork(2, 20202021)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c24fea58-d8a3-4352-a3b6-716340da74e5",
   "metadata": {},
   "source": [
    "### Read OpCreds Cluster\n",
    "\n",
    "Read out the OpCreds cluster to confirm membership into Fabric 1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "830e3421-45a6-435f-9617-bbf34f7c3fe0",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
      ],
      "text/plain": []
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\n",
       "\u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1;36m0\u001b[0m: \u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'matter.clusters.Objects.OperationalCredentials'\u001b[0m\u001b[39m>: \u001b[0m\u001b[1;39m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[39m<class \u001b[0m\u001b[32m'matter.clusters.Attribute.DataVersion'\u001b[0m\u001b[39m>: \u001b[0m\u001b[1;36m4246564825\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[39m<class \u001b[0m\u001b[32m'matter.clusters.Objects.OperationalCredentials.Attributes.Fabrics'\u001b[0m\u001b[1m>\u001b[0m: \u001b[1m[\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1;35mFabricDescriptorStruct\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mrootPublicKey\u001b[0m=\u001b[32mb\u001b[0m\u001b[32m'\\x04\\xffKd\\xd3v\\xa97c\\x87\\r\\xadXF\\xd2?\\n\\x08\\x1f\\rZE\\x91\\x0c_\\x1e`\"\\xfbwZ\\x9c\\xaf!\\\u001b[0m\u001b[32mx10\u001b[0m\u001b[32m=\\xd4\\x03\\xf5\u001b[0m\u001b[32m[\u001b[0m\u001b[32m}\u001b[0m\u001b[32m\\xb3\\x08\\xa2\\xe5\\x04\\x7f\\x06\\x1c\\nEa\\x02q\\xeeK\\x91\\xda\\x1e\\xd2\\\\i\\xef\\x05#'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mvendorID\u001b[0m=\u001b[1;36m65521\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mfabricID\u001b[0m=\u001b[1;36m1\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mnodeID\u001b[0m=\u001b[1;36m2\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mlabel\u001b[0m=\u001b[32m''\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mfabricIndex\u001b[0m=\u001b[1;36m1\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1m)\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[1m]\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[1m}\u001b[0m"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "await devCtrl.ReadAttribute(2, [(Clusters.OperationalCredentials.Attributes.Fabrics)], fabricFiltered=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "77c0c2a1-3014-4dc5-8d42-5a3459ed311a",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "### Commission onto Fabric 2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "965a5fbf-5762-4432-93f9-47782c5ee050",
   "metadata": {},
   "source": [
    "#### Create a new CertificateAuthority and a new FabricAdmin\n",
    "We create a new `CertificateAuthority` instance, and then create a new `FabricAdmin` that administers Fabric 2 within that CA."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "9f7d6810-6d8e-47c9-8795-b4bc8777e963",
   "metadata": {},
   "outputs": [],
   "source": [
    "certificateAuthority = certificateAuthorityManager.NewCertificateAuthority()\n",
    "\n",
    "fabricAdmin2 = certificateAuthority.NewFabricAdmin(vendorId=0xFFF1, fabricId=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a4fc670-3b6f-490d-a01b-621a6b086650",
   "metadata": {},
   "source": [
    "Two different `CertificateAuthority` instances are now present"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b256ca0e-0876-41e2-a414-ca1e00beeb5e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
      ],
      "text/plain": []
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\n",
       "\u001b[1m[\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mmatter.CertificateAuthority.CertificateAuthority\u001b[0m\u001b[39m object at \u001b[0m\u001b[1;36m0x74c32c8ba680\u001b[0m\u001b[39m>,\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[39m<matter.CertificateAuthority.CertificateAuthority object at \u001b[0m\u001b[1;36m0x74c32c8b9c60\u001b[0m\u001b[1m>\u001b[0m\n",
       "\u001b[1m]\u001b[0m"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "caList"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "73477a0d-f80f-4973-b34b-fe31b55cb5e1",
   "metadata": {},
   "source": [
    "Here's a brief peek at the JSON data that is in the persisted storage file."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "098c71b3-1bdd-44a2-b122-26387913bd3e",
   "metadata": {},
   "source": [
    "#### Create a new ChipDeviceController on Fabric 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "15bb2c3e-9051-421c-8769-4a59e4b2fc73",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "devCtrl2 = fabricAdmin2.NewController()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9da4943c-ffff-42e1-a369-f36f89423ed6",
   "metadata": {},
   "source": [
    "#### Open Commissioning Window"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9178e145-bbcc-463d-8ada-72b3c9575b2b",
   "metadata": {},
   "source": [
    "The Controller of Fabric 1 must open the commissioning window that allows the Commissioner of Fabric 2 to join the node to its fabric."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "7902ab28-3c74-4717-8522-f6c4a17c5efe",
   "metadata": {},
   "outputs": [],
   "source": [
    "await devCtrl.SendCommand(2, 0, Clusters.AdministratorCommissioning.Commands.OpenBasicCommissioningWindow(180),  timedRequestTimeoutMs=10000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "1c57c8ff-5ae9-4fdd-9fb8-4eda0e297db2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
      ],
      "text/plain": []
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001b[1;36m2\u001b[0m"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "await devCtrl2.CommissionOnNetwork(2, 20202021)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d55534a4-a926-42da-8b80-a9b3408324dc",
   "metadata": {},
   "source": [
    "### Read OpCreds Cluster\n",
    "\n",
    "Read out the OpCreds cluster to confirm membership into Fabric 2."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "0c087a70-d852-4329-958d-d91a1bdbffaf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
      ],
      "text/plain": []
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\n",
       "\u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1;36m0\u001b[0m: \u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'matter.clusters.Objects.OperationalCredentials'\u001b[0m\u001b[39m>: \u001b[0m\u001b[1;39m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[39m<class \u001b[0m\u001b[32m'matter.clusters.Attribute.DataVersion'\u001b[0m\u001b[39m>: \u001b[0m\u001b[1;36m4246564829\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[39m<class \u001b[0m\u001b[32m'matter.clusters.Objects.OperationalCredentials.Attributes.Fabrics'\u001b[0m\u001b[1m>\u001b[0m: \u001b[1m[\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1;35mFabricDescriptorStruct\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mrootPublicKey\u001b[0m=\u001b[32mb\u001b[0m\u001b[32m'\\x04\\xffKd\\xd3v\\xa97c\\x87\\r\\xadXF\\xd2?\\n\\x08\\x1f\\rZE\\x91\\x0c_\\x1e`\"\\xfbwZ\\x9c\\xaf!\\\u001b[0m\u001b[32mx10\u001b[0m\u001b[32m=\\xd4\\x03\\xf5\u001b[0m\u001b[32m[\u001b[0m\u001b[32m}\u001b[0m\u001b[32m\\xb3\\x08\\xa2\\xe5\\x04\\x7f\\x06\\x1c\\nEa\\x02q\\xeeK\\x91\\xda\\x1e\\xd2\\\\i\\xef\\x05#'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mvendorID\u001b[0m=\u001b[1;36m65521\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mfabricID\u001b[0m=\u001b[1;36m1\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mnodeID\u001b[0m=\u001b[1;36m2\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mlabel\u001b[0m=\u001b[32m''\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mfabricIndex\u001b[0m=\u001b[1;36m1\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1m)\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1;35mFabricDescriptorStruct\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mrootPublicKey\u001b[0m=\u001b[32mb\u001b[0m\u001b[32m'\\x04pKSE\\xb6\\x07\\x04\\n\\xa5p\\xbb\\x1f\\xa0Z\\xb8HS\\xaa\\xaa\\xe9|\\xf1\\xaf+\\x0e\\xa6\u001b[0m\u001b[32m]\u001b[0m\u001b[32m 7\\x8f\\x10\\xe5\\xa6\\xb6\\x15$k\\x08#X\\xa5\\x8f+\\xd3M\\x99\\x06\\xc1\\x86\\x8e\\xda\\xd3\u001b[0m\u001b[32m{\u001b[0m\u001b[32m&\\xaf\u001b[0m\u001b[32m)\u001b[0m\u001b[32m\\x81\\xa1h\\xc7$\\xc0\\xad\\x9b'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mvendorID\u001b[0m=\u001b[1;36m65521\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mfabricID\u001b[0m=\u001b[1;36m2\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mnodeID\u001b[0m=\u001b[1;36m2\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mlabel\u001b[0m=\u001b[32m''\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mfabricIndex\u001b[0m=\u001b[1;36m2\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1m)\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[1m]\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[1m}\u001b[0m"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "await devCtrl2.ReadAttribute(2, [(Clusters.OperationalCredentials.Attributes.Fabrics)], fabricFiltered=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b5cbbd20-1609-4fe1-a17e-8027b0ba1334",
   "metadata": {
    "tags": []
   },
   "source": [
    "## Relaunch REPL\n",
    "\n",
    "Let's simulate re-launching the REPL to show-case the capabilities of the persistence storage and its mechanics."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "d44f5ab8-c59f-4fdb-9a26-081f6799c512",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "<span style=\"font-weight: bold\"> Replacing </span> store path .<span style=\"color: #800080; text-decoration-color: #800080\">/credentials/development/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">paa-root-certs</span> with \n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">/home/root/repos/connectedhomeip/credentials/development/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">paa-root-certs</span>\n",
       "Note that you are still running from \n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">/home/root/repos/connectedhomeip/docs/development_controllers/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">matter-repl</span> so other relative\n",
       "paths may be off.\n",
       "                    \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n",
       "\u001b[1m Replacing \u001b[0m store path .\u001b[35m/credentials/development/\u001b[0m\u001b[95mpaa-root-certs\u001b[0m with \n",
       "\u001b[35m/home/root/repos/connectedhomeip/credentials/development/\u001b[0m\u001b[95mpaa-root-certs\u001b[0m\n",
       "Note that you are still running from \n",
       "\u001b[35m/home/root/repos/connectedhomeip/docs/development_controllers/\u001b[0m\u001b[95mmatter-repl\u001b[0m so other relative\n",
       "paths may be off.\n",
       "                    \n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #00ff00; text-decoration-color: #00ff00\">─────────────────────────────────────────────────── </span>Matter REPL<span style=\"color: #00ff00; text-decoration-color: #00ff00\"> ───────────────────────────────────────────────────</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[92m─────────────────────────────────────────────────── \u001b[0mMatter REPL\u001b[92m ───────────────────────────────────────────────────\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "            \n",
       "\n",
       "<span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">            Welcome to the Matter Python REPL!</span>\n",
       "\n",
       "<span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">            For help, please type </span><span style=\"color: #008000; text-decoration-color: #008000; font-weight: bold\">matterhelp()</span>\n",
       "\n",
       "<span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">            To get more information on a particular object/class, you can pass</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">            that into </span><span style=\"color: #008000; text-decoration-color: #008000; font-weight: bold\">matterhelp()</span><span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\"> as well.</span>\n",
       "\n",
       "<span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">            </span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n",
       "            \n",
       "\n",
       "\u001b[1;34m            Welcome to the Matter Python REPL!\u001b[0m\n",
       "\n",
       "\u001b[1;34m            For help, please type \u001b[0m\u001b[1;32mmatterhelp\u001b[0m\u001b[1;32m(\u001b[0m\u001b[1;32m)\u001b[0m\n",
       "\n",
       "\u001b[1;34m            To get more information on a particular object/class, you can pass\u001b[0m\n",
       "\u001b[1;34m            that into \u001b[0m\u001b[1;32mmatterhelp\u001b[0m\u001b[1;32m(\u001b[0m\u001b[1;32m)\u001b[0m\u001b[1;34m as well.\u001b[0m\n",
       "\n",
       "\u001b[1;34m            \u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #00ff00; text-decoration-color: #00ff00\">───────────────────────────────────────────────────────────────────────────────────────────────────────────────────</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[92m───────────────────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">The following objects have been created:</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n",
       "\n",
       "\u001b[34mThe following objects have been created:\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">        <span style=\"color: #800000; text-decoration-color: #800000\">certificateAuthorityManager</span><span style=\"color: #000080; text-decoration-color: #000080\">:    Manages a list of CertificateAuthority instances.</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">        </span><span style=\"color: #800000; text-decoration-color: #800000\">caList</span><span style=\"color: #000080; text-decoration-color: #000080\">:                         The list of CertificateAuthority instances.</span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">        </span><span style=\"color: #800000; text-decoration-color: #800000\">caList</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">[</span><span style=\"color: #800000; text-decoration-color: #800000\">n</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">]</span><span style=\"color: #800000; text-decoration-color: #800000\">.adminList</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">[</span><span style=\"color: #800000; text-decoration-color: #800000\">m</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">]</span><span style=\"color: #000080; text-decoration-color: #000080\">:         A specific FabricAdmin object at index m for the nth CertificateAuthority </span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">instance.</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "        \u001b[31mcertificateAuthorityManager\u001b[0m\u001b[34m:    \u001b[0m\u001b[34mManages a list of CertificateAuthority instances.\u001b[0m\n",
       "\u001b[34m        \u001b[0m\u001b[31mcaList\u001b[0m\u001b[34m: \u001b[0m\u001b[34m        \u001b[0m\u001b[34m        \u001b[0m\u001b[34m        \u001b[0m\u001b[34mThe list of CertificateAuthority instances.\u001b[0m\n",
       "\u001b[34m        \u001b[0m\u001b[31mcaList\u001b[0m\u001b[1;31m[\u001b[0m\u001b[31mn\u001b[0m\u001b[1;31m]\u001b[0m\u001b[31m.adminList\u001b[0m\u001b[1;31m[\u001b[0m\u001b[31mm\u001b[0m\u001b[1;31m]\u001b[0m\u001b[34m: \u001b[0m\u001b[34m        \u001b[0m\u001b[34mA specific FabricAdmin object at index m for the nth CertificateAuthority \u001b[0m\n",
       "\u001b[34minstance.\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "\n",
       "<span style=\"color: #000080; text-decoration-color: #000080\">Default CHIP Device Controller </span><span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">(</span><span style=\"color: #000080; text-decoration-color: #000080\">NodeId: </span><span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">112233</span><span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">)</span><span style=\"color: #000080; text-decoration-color: #000080\">: has been initialized to manage </span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">caList[</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">0</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">].adminList[</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">0</span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">]</span><span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\"> (FabricId = </span>\n",
       "<span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">1</span><span style=\"color: #000080; text-decoration-color: #000080; font-weight: bold\">), and is available as </span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">devCtrl</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n",
       "\n",
       "\u001b[34mDefault CHIP Device Controller \u001b[0m\u001b[1;34m(\u001b[0m\u001b[34mNodeId: \u001b[0m\u001b[1;34m112233\u001b[0m\u001b[1;34m)\u001b[0m\u001b[34m: has been initialized to manage \u001b[0m\u001b[1;31mcaList\u001b[0m\u001b[1;31m[\u001b[0m\u001b[1;31m0\u001b[0m\u001b[1;31m]\u001b[0m\u001b[1;31m.adminList\u001b[0m\u001b[1;31m[\u001b[0m\u001b[1;31m0\u001b[0m\u001b[1;31m]\u001b[0m\u001b[1;34m \u001b[0m\u001b[1;34m(\u001b[0m\u001b[1;34mFabricId = \u001b[0m\n",
       "\u001b[1;34m1\u001b[0m\u001b[1;34m)\u001b[0m\u001b[1;34m, and is available as \u001b[0m\u001b[1;31mdevCtrl\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%reset -f\n",
    "import importlib.util\n",
    "spec = importlib.util.find_spec('matter.ReplStartup')\n",
    "%run {spec.origin}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2a619893-da3f-4651-bc9f-a2276906fc71",
   "metadata": {},
   "source": [
    "The REPL now loaded (through the `certificateAuthorityManager`) the two `certificateAuthority` instances that were created in the previous session into the `CaList`. It has also created a default controller on the first fabric in that list (Fabric 1) as `devCtrl`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "cb277ac7-2660-45bc-a01e-8a0e543ea53f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
      ],
      "text/plain": []
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\n",
       "\u001b[1m[\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mmatter.CertificateAuthority.CertificateAuthority\u001b[0m\u001b[39m object at \u001b[0m\u001b[1;36m0x74c32c96dc30\u001b[0m\u001b[39m>,\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[39m<matter.CertificateAuthority.CertificateAuthority object at \u001b[0m\u001b[1;36m0x74c32c96d720\u001b[0m\u001b[1m>\u001b[0m\n",
       "\u001b[1m]\u001b[0m"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "caList"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1f97206d-2b2f-4ae2-8814-5c756b514ca1",
   "metadata": {
    "tags": []
   },
   "source": [
    "### Establish CASE and Read OpCreds\n",
    "\n",
    "To prove that we do indeed have two distinct fabrics and controllers on each fabric, let's go ahead and update the label of each fabric. To do so, you'd need to successfully establish a CASE session through a controller on the respective fabric, and call the 'UpdateLabel' command.\n",
    "\n",
    "Underneath the covers, each device controller will do operational discovery of the NodeId being read and establish a CASE session before issuing the IM interaction."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "fb79f13a-9acb-4ddd-b0b4-38589ff4822e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
      ],
      "text/plain": []
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001b[1m<\u001b[0m\u001b[1;95mmatter.ChipDeviceCtrl.ChipDeviceController\u001b[0m\u001b[39m object at \u001b[0m\u001b[1;36m0x74c32c96e0b0\u001b[0m\u001b[1m>\u001b[0m"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "devCtrl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "45ee5838-b1e9-4ba8-b804-c3efc9d352d0",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
      ],
      "text/plain": []
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\n",
       "\u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1;36m0\u001b[0m: \u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'matter.clusters.Objects.OperationalCredentials'\u001b[0m\u001b[39m>: \u001b[0m\u001b[1;39m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[39m<class \u001b[0m\u001b[32m'matter.clusters.Attribute.DataVersion'\u001b[0m\u001b[39m>: \u001b[0m\u001b[1;36m4246564830\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[39m<class \u001b[0m\u001b[32m'matter.clusters.Objects.OperationalCredentials.Attributes.Fabrics'\u001b[0m\u001b[1m>\u001b[0m: \u001b[1m[\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1;35mFabricDescriptorStruct\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mrootPublicKey\u001b[0m=\u001b[32mb\u001b[0m\u001b[32m'\\x04\\xffKd\\xd3v\\xa97c\\x87\\r\\xadXF\\xd2?\\n\\x08\\x1f\\rZE\\x91\\x0c_\\x1e`\"\\xfbwZ\\x9c\\xaf!\\\u001b[0m\u001b[32mx10\u001b[0m\u001b[32m=\\xd4\\x03\\xf5\u001b[0m\u001b[32m[\u001b[0m\u001b[32m}\u001b[0m\u001b[32m\\xb3\\x08\\xa2\\xe5\\x04\\x7f\\x06\\x1c\\nEa\\x02q\\xeeK\\x91\\xda\\x1e\\xd2\\\\i\\xef\\x05#'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mvendorID\u001b[0m=\u001b[1;36m65521\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mfabricID\u001b[0m=\u001b[1;36m1\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mnodeID\u001b[0m=\u001b[1;36m2\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mlabel\u001b[0m=\u001b[32m'Fabric1Label'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mfabricIndex\u001b[0m=\u001b[1;36m1\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1m)\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1;35mFabricDescriptorStruct\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mrootPublicKey\u001b[0m=\u001b[32mb\u001b[0m\u001b[32m'\\x04pKSE\\xb6\\x07\\x04\\n\\xa5p\\xbb\\x1f\\xa0Z\\xb8HS\\xaa\\xaa\\xe9|\\xf1\\xaf+\\x0e\\xa6\u001b[0m\u001b[32m]\u001b[0m\u001b[32m 7\\x8f\\x10\\xe5\\xa6\\xb6\\x15$k\\x08#X\\xa5\\x8f+\\xd3M\\x99\\x06\\xc1\\x86\\x8e\\xda\\xd3\u001b[0m\u001b[32m{\u001b[0m\u001b[32m&\\xaf\u001b[0m\u001b[32m)\u001b[0m\u001b[32m\\x81\\xa1h\\xc7$\\xc0\\xad\\x9b'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mvendorID\u001b[0m=\u001b[1;36m65521\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mfabricID\u001b[0m=\u001b[1;36m2\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mnodeID\u001b[0m=\u001b[1;36m2\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mlabel\u001b[0m=\u001b[32m''\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mfabricIndex\u001b[0m=\u001b[1;36m2\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1m)\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[1m]\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[1m}\u001b[0m"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "await devCtrl.SendCommand(2, 0, Clusters.OperationalCredentials.Commands.UpdateFabricLabel(\"Fabric1Label\"))\n",
    "await devCtrl.ReadAttribute(2, [(Clusters.OperationalCredentials.Attributes.Fabrics)], fabricFiltered=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ea5d9a2b-78b2-4bb9-843e-97d26b1c0f90",
   "metadata": {
    "tags": []
   },
   "source": [
    "Instantiate a controller on fabric 2 and use it to read out the op creds from that fabric."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "5d88cb17-bdda-418f-94ca-83d746c162b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
      ],
      "text/plain": []
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\n",
       "\u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1;36m0\u001b[0m: \u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'matter.clusters.Objects.OperationalCredentials'\u001b[0m\u001b[39m>: \u001b[0m\u001b[1;39m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[39m<class \u001b[0m\u001b[32m'matter.clusters.Attribute.DataVersion'\u001b[0m\u001b[39m>: \u001b[0m\u001b[1;36m4246564831\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[39m<class \u001b[0m\u001b[32m'matter.clusters.Objects.OperationalCredentials.Attributes.Fabrics'\u001b[0m\u001b[1m>\u001b[0m: \u001b[1m[\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1;35mFabricDescriptorStruct\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mrootPublicKey\u001b[0m=\u001b[32mb\u001b[0m\u001b[32m'\\x04\\xffKd\\xd3v\\xa97c\\x87\\r\\xadXF\\xd2?\\n\\x08\\x1f\\rZE\\x91\\x0c_\\x1e`\"\\xfbwZ\\x9c\\xaf!\\\u001b[0m\u001b[32mx10\u001b[0m\u001b[32m=\\xd4\\x03\\xf5\u001b[0m\u001b[32m[\u001b[0m\u001b[32m}\u001b[0m\u001b[32m\\xb3\\x08\\xa2\\xe5\\x04\\x7f\\x06\\x1c\\nEa\\x02q\\xeeK\\x91\\xda\\x1e\\xd2\\\\i\\xef\\x05#'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mvendorID\u001b[0m=\u001b[1;36m65521\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mfabricID\u001b[0m=\u001b[1;36m1\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mnodeID\u001b[0m=\u001b[1;36m2\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mlabel\u001b[0m=\u001b[32m'Fabric1Label'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mfabricIndex\u001b[0m=\u001b[1;36m1\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1m)\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1;35mFabricDescriptorStruct\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mrootPublicKey\u001b[0m=\u001b[32mb\u001b[0m\u001b[32m'\\x04pKSE\\xb6\\x07\\x04\\n\\xa5p\\xbb\\x1f\\xa0Z\\xb8HS\\xaa\\xaa\\xe9|\\xf1\\xaf+\\x0e\\xa6\u001b[0m\u001b[32m]\u001b[0m\u001b[32m 7\\x8f\\x10\\xe5\\xa6\\xb6\\x15$k\\x08#X\\xa5\\x8f+\\xd3M\\x99\\x06\\xc1\\x86\\x8e\\xda\\xd3\u001b[0m\u001b[32m{\u001b[0m\u001b[32m&\\xaf\u001b[0m\u001b[32m)\u001b[0m\u001b[32m\\x81\\xa1h\\xc7$\\xc0\\xad\\x9b'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mvendorID\u001b[0m=\u001b[1;36m65521\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mfabricID\u001b[0m=\u001b[1;36m2\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mnodeID\u001b[0m=\u001b[1;36m2\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mlabel\u001b[0m=\u001b[32m'Fabric2Label'\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mfabricIndex\u001b[0m=\u001b[1;36m2\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1m)\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[1m]\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[1m}\u001b[0m"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fabricAdmin2 = caList[1].adminList[0]\n",
    "devCtrl2 = fabricAdmin2.NewController()\n",
    "\n",
    "await devCtrl2.SendCommand(2, 0, Clusters.OperationalCredentials.Commands.UpdateFabricLabel(\"Fabric2Label\"))\n",
    "await devCtrl2.ReadAttribute(2, [(Clusters.OperationalCredentials.Attributes.Fabrics)], fabricFiltered=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "4ecb4ab4-bb7a-4941-8080-34783028fce0",
   "metadata": {},
   "outputs": [],
   "source": [
    "devCtrl2.Shutdown()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
